package com.lowang.test.springmvc.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.lowang.test.springmvc.cache.CachedEvict;
import com.lowang.test.springmvc.cache.Cached;
import com.lowang.test.springmvc.dao.IUserDao;
import com.lowang.test.springmvc.domain.User;
import com.lowang.test.springmvc.exception.AppException;
import com.lowang.test.springmvc.service.IUserService;

@Service("userService")
public class UserServiceImpl implements IUserService {
  @Autowired private IUserDao userDao;

  @Override
  @Cached(key = "#user.id")
  @Transactional
  public List<User> list(User user) throws AppException {
    return userDao.list(user);
  }

  @Override
  @Transactional
  public User add(User user) throws AppException {
    return userDao.add(user);
  }

  @Override
  public User delete(Long id) throws AppException {
    return userDao.delete(id);
  }

  @Override
  @CachedEvict(key = "#user.id")
  public User update(User user) throws AppException {
    return userDao.update(user);
  }
}
